#include "serialthread.h"

SerialThread::SerialThread()
{
    struct PortSettings m_GPRS_Com_Setting={BAUD115200,DATA_8,PAR_NONE,STOP_1,FLOW_OFF,10};

    //这里注意加入的时间不同界面的反应可能不一致，这个数字大的话界面反应显示可能会感觉卡
        m_GPRS_Com=new Posix_QextSerialPort("/dev/ttyS0",m_GPRS_Com_Setting,QextSerialBase::Polling);
        m_GPRS_Com->open(QIODevice::ReadWrite);//返回布尔类型，打开成功是true打开失败是false
        GPRS_LenOld = 0;/*在构造函数内赋初值*/
        statusCount = 0;
        statusEmitDisconnect = 0;
    }
    //析够函数
    SerialThread::~SerialThread()
    {

    }
    //线程启动函数
    void SerialThread::run()
    {
        QByteArray temp ;
        while(true)
        {
          qint64 GPRS_Len=m_GPRS_Com->size();

          if((GPRS_LenOld==GPRS_Len)&&(GPRS_LenOld>0))
          {
          //读取串口缓冲区的所有数据给临时变量temp
             temp = m_GPRS_Com->readAll();
              //然后写入FIFO
              //再置
              emit this->m_GPRS_Done_CardReader(temp);
                statusCount =0;
          }
          else
          {
              GPRS_LenOld=GPRS_Len;
              statusCount ++;
              if(statusCount >500){
                  if(0==statusEmitDisconnect){
                    emit this->m_GPRS_Disconnect_CardReader();
                  }
                  statusEmitDisconnect = 1;
              }
          }
          msleep(10);//睡眠10ms
        }
}

